package com.ant.storage.service.impl;

import com.ant.storage.dto.SupplysideIndustryDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.mapper.SupplysideIndustryMapper;
import com.ant.storage.pojo.SupplysideIndustry;
import com.ant.storage.service.ISupplysideIndustryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzd
 * @since 2025-10-31
 */
@Service
public class SupplysideIndustryServiceImpl extends ServiceImpl<SupplysideIndustryMapper, SupplysideIndustry> implements ISupplysideIndustryService {

    @Override
    public SupplysideIndustry saveSupplysideIndustry(SupplysideIndustryDto dto) {
        if(dto.getCompanyId()==null){
            throw new AntException("请选择企业");
        }
        SupplysideIndustry year = new SupplysideIndustry();
        year.setIndustry(dto.getIndustry());
        year.setCompanyId(dto.getCompanyId());
        year.setIndustryName(dto.getIndustryName());
        year.setIndustryCode(dto.getIndustryCode());
        year.setProductName(dto.getProductName());
        year.setProductPrice(dto.getProductPrice());
        year.setVocUnit(dto.getVocUnit());
        year.setCreationTime(LocalDateTime.now());
        if(dto.getId()==null){
            baseMapper.insert(year);
        }else{
            baseMapper.updateById(year);
        }
        return year;
    }

    @Override
    public List<SupplysideIndustry> listById(Integer id) {



        return baseMapper.selectList(new QueryWrapper<SupplysideIndustry>().eq("company_id", id));
    }
}
